package com.pr.makfilm.dao.impl;

import com.pr.makfilm.dao.IEventDao;
import com.pr.makfilm.domain.Event;
import com.pr.makfilm.domain.Room;
import com.pr.makfilm.domain.filter.AbstractFilter;
import com.pr.makfilm.domain.filter.EventFilter;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 * Created with IntelliJ IDEA.
 * User: Pawel
 * Date: 17.09.13
 * Time: 23:19
 * To change this template use File | Settings | File Templates.
 */
@Repository(EventDaoImpl.BEAN_NAME)
public class EventDaoImpl extends AbstractDaoImpl<Event> implements IEventDao
{
   public static final String BEAN_NAME = "eventDao";

   @Override
   public Criteria createCriteriaFromSearchParams(AbstractFilter abstractFilter)
   {
      Criteria criteria = createCriteria();
      EventFilter filter = (EventFilter) abstractFilter;

      Room room = filter.getRoom();
      if (room != null)
      {
         criteria.add(Restrictions.eq(Event.FIELD_ROOM, room));
      }


      return super.createCriteriaFromSearchParams(abstractFilter);
   }
}
